package com.jx.tool.utils;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FileFinder implements FilenameFilter {
	private String end;
	
	public FileFinder(String end) {
		this.end = end;
	}

	public boolean accept(File dir, String name) {
		return name.endsWith(end);
	}
	
	public List<File> find(File dir) {
		File[] files = dir.listFiles();
		List<File> list = new ArrayList<File>();
		list.addAll(Arrays.asList(dir.listFiles(this)));
		for(int i = 0; i < files.length; i++) {
			File file = files[i];
			if(file.isDirectory()) {
				list.addAll(find(file));
			}
		}
		return list;
	}
	
	public static void main(String[] args) {
		FileFinder finder = new FileFinder(".java");
		List<File> files = finder.find(new File("."));
		for(File file : files) {
			System.out.println(file.getPath());
		}
	}

}
